package com.siyu.basedata.rainsence.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.siyu.common.core.controller.BaseController;
import com.siyu.common.core.domain.AjaxResult;
import com.siyu.common.core.page.TableDataInfo;
import com.siyu.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.siyu.basedata.rainsence.domain.RainSence;
import com.siyu.basedata.rainsence.service.IRainSenceService;

/**
 * 降雨情景Controller
 *
 * @author hrhy
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/basedata/RainSence")
public class RainSenceController extends BaseController {
    @Autowired
    private IRainSenceService rainSenceService;

    /**
     * 查询降雨情景列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RainSence rainSence) {
        startPage();
        List<RainSence> list = rainSenceService.selectRainSenceList(rainSence);
        return getDataTable(list);
    }

    /**
     * 导出降雨情景列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, RainSence rainSence) {
        List<RainSence> list = rainSenceService.selectRainSenceList(rainSence);
        ExcelUtil<RainSence> util = new ExcelUtil<RainSence>(RainSence.class);
        util.exportExcel(response, list, "降雨情景数据");
    }

    /**
     * 获取降雨情景详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(rainSenceService.selectRainSenceById(id));
    }

    /**
     * 新增降雨情景
     */
    @PostMapping
    public AjaxResult add(@RequestBody RainSence rainSence) {
        return toAjax(rainSenceService.insertRainSence(rainSence));
    }

    /**
     * 修改降雨情景
     */
    @PutMapping
    public AjaxResult edit(@RequestBody RainSence rainSence) {
        return toAjax(rainSenceService.updateRainSence(rainSence));
    }

    /**
     * 删除降雨情景
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(rainSenceService.deleteRainSenceByIds(ids));
    }
}
